package com.student.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.student.dao.StudentDao;
import com.student.entity.StudentInfo;

public class StudentListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	public StudentListServlet() {
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		StudentDao studao = new StudentDao(); 
		request.setCharacterEncoding("utf-8");

		List<StudentInfo> stus = studao.queryAll();

		// 将 stus集合设置为setAttribute 方便获取
		request.setAttribute("students", stus);
		

		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
